<template>
    <basic-container>
        <div class="card-border">
            <card-header :header-data="headerData"></card-header>
            <avue-crud :data="dataDialog"
                       :option="optionDialog"
                       :page="pagedialog"
                       :table-loading="Loadingdialog"
                       @size-change="sizeChange"
                       @current-change="currentChange"
                       @search-change="searchChange"
                       @search-reset="searchReset"
                       class="avuecrud">
            </avue-crud>
        </div>
    </basic-container>
</template>
<script>
    import { projectRegister } from "@/api/planning/project";
    import { listInquire } from "@/api/planning/detailList";
    export default {
        name: "reply",
        created(){
            this.getListDialog(this.pagedialog)
            window.listDetail = this.listDetail;
        },
        data() {
            return {
                headerData:{
                    title:'清单查询',
                },
                dataDialog:[],
                optionDialog: {
                    page: true,
                    addBtn: false,
                    editBtn: false,
                    addRowBtn: false,
                    indexLabel: "序号",
                    index: true,
                    indexWidth:70,
                    cellBtn: false,
                    delBtn: false,
                    menuWidth: 100,
                    columnBtn: false,
                    menu:false,
                    refreshBtn: false,
                    filterBtn: false,
                    searchBtn: false,
                    keyId: "id",
                    column: [
                        {
                            label: "清单编号",
                            width: 240,
                            prop: "code",
                            cell: true,
                        },
                        {
                            label: "清单标题",
                            prop: "title",
                            cell: true,
                            formatter: function (row, value, label, column) {
                                let a = '<a style="cursor: pointer;" onclick="listDetail(\'' + row.id;
                                if (row.processId != null) {
                                    a += '\',\'' + row.processId;
                                }
                                a += '\')">' + value + '</a>';
                                return a;
                            }
                        },
                        {
                            label: "清单标题",
                            prop: "titleLike",
                            cell: true,
                            search:true,
                            hide: true,
                        },
                    ]
                },
                pagedialog : {
                    total: 0, // 总页数pagedialog
                    currentPage: 1, // 当前页数
                    pageSize: 10 // 每页显示多少条
                },
                Loadingdialog: false,
                titleLikeSearch:''
            };
        },
        methods: {
            listDetail(id, processId) {
                let src = `/listdetail/detail/${id}`;
                this.$router.push({
                    path: src,
                    query: {processId: processId}
                });
            },
            getListDialog(page, params){
                this.Loadingdialog = true;
                listInquire(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                },params)).then(response => {
                    this.dataDialog = response.data.data.records;
                    this.pagedialog.total = response.data.data.total;
                    this.Loadingdialog = false;
                })
            },
            searchReset() {
                this.titleLikeSearch = '';
                let params = {
                    titleLike:this.titleLikeSearch,
                };
                this.getListDialog(this.pagedialog,params)
            },

            //搜索回调
            searchChange(params){
                this.pagedialog.currentPage = 1
                this.getListDialog(this.pagedialog,this.dealSearchParam(params));
            },
            // 处理搜索过滤
            dealSearchParam(params){
                if(params.titleLike){
                    params.titleLike = params.titleLike;
                }
                this.titleLikeSearch = params.titleLike;
                return params;
            },
            currentChange(currentPage) {
                var page = this.pagedialog;
                page.currentPage = currentPage;
                let params = {
                    titleLike:this.titleLikeSearch,
                };
                this.getListDialog(page,params);
            },
            sizeChange(pageSize) {
                var page = this.pagedialog;
                page.pageSize = pageSize;
                let params = {
                    titleLike:this.titleLikeSearch,
                };
                this.getListDialog(page,params);
            },
        }
    };
</script>

<style lang="scss" scoped>
    .card-border {
        padding: 10px;
        border: 1px solid #d2d2d2;
    }
    .card-body {
        padding: 10px;
    }
    .menu-title {
        float: left;
        margin-right: 6px;
    }
    .menu-title-img {
        width: 25px;
        position: relative;
        top: 7px;
    }
    .menu-title-text {
        display: inline-block;
        font-size: 15px;
        font-weight: 600;
        margin-left: 0.2rem;
    }

</style>
